package uk.co.q3c.deplan.server.unit.domain.util.shard;

import org.testng.Assert;
import org.testng.annotations.Test;

import uk.co.q3c.deplan.client.dao.ResourceService;
import uk.co.q3c.deplan.client.service.TaskService;
import uk.co.q3c.deplan.server.dao.AdminDao;
import uk.co.q3c.deplan.server.unit.dao.LocalDatastoreTestCase;

/**
 * Functionality moved from a dedicated class to the Dao layer, but this test case retained.
 * 
 * @author David Sowerby 1 Mar 2010
 * 
 */
@Test
public class ShardedCounter_UT extends LocalDatastoreTestCase {
	TaskService taskDao;
	ResourceService resourceDao;
	AdminDao adminDao;
	final String counterName = "testCounter";

	@Override
	protected void beforeMethod() throws Exception {
		super.beforeMethod();
		taskDao = connection.taskService();
		resourceDao = connection.resourceService();
		adminDao = connection.adminDao();
	}

	/**
	 * Not using sharded counters for domain object ids any more, so this is a straight test of the counters themselves.
	 */
	public void basicCounting() {
		// done as part of LocalDatastoreTestCase
		// Server.initialiseCounters();
		// Test isolation, but note that initialising the database causes some to increment
		adminDao.createCounter(counterName);
		Assert.assertEquals(adminDao.counterValue(counterName), 0);
		adminDao.incrementCounter(counterName);
		Assert.assertEquals(adminDao.counterValue(counterName), 1);
		Assert.assertEquals(adminDao.incrementCounter(counterName), 2);
	}
}
